package com.eight.travel.service.impl;

import com.eight.travel.dao.HotelDao;
import com.eight.travel.pojo.Hotel;
import com.eight.travel.pojo.User;
import com.eight.travel.service.OrderRoomService;
import com.eight.travel.utils.BaseResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderRoomImpl implements OrderRoomService {
    @Autowired
    HotelDao hotelDao;
    @Autowired
    OrderRoomImpl orderRoomImpl;
    private BaseResp baseResp =new BaseResp();
    private static Integer roomnumber=1;
    @Override
    public BaseResp qgendroom(List<User> user, Integer hid) {
        Hotel hotel = hotelDao.orderRoom(hid);
        roomnumber = hotel.getHnumroom();
        for (User useri : user) {
            new Thread(orderRoomImpl,useri.getUsername()).start();
        }
//        return baseResp.setData(this.run());
return null;
    }


    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (this) {
                roomnumber--;
                if (roomnumber <= 0) {
                    break;
                }
                System.out.println(Thread.currentThread().getName() + "拿到了最后房子");
            }
        }
    }
}
